* make dataset vertical with all single item w1 measures in col1, and w2 measures in col2. Individual revealed reliability is the correlation of the two vectors (columns), generated below. 


cd ""
clear 
set more off

use data_all_vars
* For robustness with the 21 non-personality indicators (table A.12)
local i=1
foreach var of varlist   GPS_risk GPS_time  GPS_pres_bias GPS_alt GPS_trust GPS_pos_rec GPS_neg_rec_self GPS_neg_rec_self2 GPS_neg_rec_other      LS_gen section4* cog_*  { 
	rename `var' wa1_`i' 
	rename w2_`var' wa2_`i'
	local++i
}


* standardizing for comparability 
foreach var of varlist wa1_* wa2_*  {
	sum `var' if `var'!=.
	replace `var'=(`var'-`r(mean)')/`r(sd)' if `var'!=.
	}

keep CID wa1_* wa2_*

*** only want individuals who participated in both survey waves
keep if wa2_1!=.


gen ind_id=_n

reshape long wa1_ wa2_, i(CID ind_id) j(item) 

sort CID item


* revealed individual reliability
gen tr_ind=.


gen long CID_corr=.
forvalues i=1(1)651 {
	capture corr  wa1_ wa2_ if ind_id==`i'
	replace tr_ind=`r(rho)' in `i'
	sum CID if ind_id==`i'
	replace CID_corr=`r(mean)' in `i'
}

keep tr_ind CID_corr
rename CID_corr CID

drop if CID==.

sort CID


save corrs_ind, replace





*** merge back individual measures for use in regression analysis
clear
use data_all_vars

sort CID
merge 1:1 CID using corrs_ind

keep if _merge==3
drop _merge


* puts BFI reliability on same scale as overall reliability	
foreach var in weight_w1w2_sure_pers {
    replace `var'=2*`var'
}
* continuous variable combining both self-reported reliability questions
gen w1w2_accuracy=w1w2_reliable+w1w2_sure_pers

*** normalize combined self-reported reliability 
foreach var of varlist  w1w2_accuracy {
	sum `var' if `var'!=.
	replace `var'=(`var'-`r(mean)')/`r(sd)' if `var'!=.
	
	}	

******************************* Exhibits Start ************************************************************************************



**************** Below Generates A.12
foreach var of varlist tr_ind  {
	reg `var' w1w2_sure_pers
	outreg2 using reg_`var'_holdout.xls, replace dec(2) noomitted

	reg `var' w1w2_reliable
	outreg2 using reg_`var'_holdout.xls, append dec(2) noomitted

	reg `var'  c.w1w2_reliable##c.w1w2_sure_pers
	outreg2 using reg_`var'_holdout.xls, append dec(2) noomitted sortvar( w1w2_sure_pers w1w2_reliable)


}

	